﻿Public Class TenKeyLabel
    'Implements IfTenkeyLabel

    Private dfltColor As Drawing.Color = Color.Yellow
    Private InputColor As Drawing.Color = Color.Cyan
    Private ErrorColor As Drawing.Color = Color.Red

    Public Enum TenkeyType
        INT
        FLT
        TYP
    End Enum

    Private fIsChanged As Boolean = False
    Private fIsEditing As Boolean = False
    Private keyType As TenkeyType = TenkeyType.FLT
    Private fAllowMinus As Boolean = True

    Public Event InputCompleted(ByVal Sender As Object)



    Public Sub New()

        ' この呼び出しはデザイナーで必要です。
        InitializeComponent(True)

        ' InitializeComponent() 呼び出しの後で初期化を追加します。

    End Sub

    Public Sub New(ByVal fBorder As Boolean)

        ' この呼び出しはデザイナーで必要です。
        InitializeComponent(fBorder)

        ' InitializeComponent() 呼び出しの後で初期化を追加します。

    End Sub

    Public Property InputLabel As Label
        Get
            Return Me
        End Get
        Set(ByVal value As Label)

        End Set
    End Property

    ''' <summary>
    ''' INT:整数、FLT:実数、TYP:型番
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Type As TenkeyType
        Get
            Return keyType
        End Get
        Set(ByVal value As TenkeyType)
            keyType = value
        End Set
    End Property

    ''' <summary>
    ''' マイナスを許可するかどうかの設定或いは取得
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AllowMinus As Boolean
        Get
            Return fAllowMinus
        End Get
        Set(ByVal value As Boolean)
            fAllowMinus = value
        End Set
    End Property

    Public ReadOnly Property IsEditing As Boolean ' Implements IfTenkeyLabel.IsEditing
        Get
            IsEditing = fIsEditing
        End Get
    End Property

    ''' <summary>
    ''' 文字が編集されたかどうかを取得する
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property IsChanged As Boolean ' Implements IfTenkeyLabel.IsChanged
        Get
            IsChanged = fIsChanged
        End Get
    End Property

    'Public Overrides Property BackColor As System.Drawing.Color
    '    Get
    '        Return MyBase.BackColor
    '    End Get
    '    Set(ByVal value As System.Drawing.Color)
    '        MyBase.BackColor = value
    '    End Set
    'End Property

    Public Property DefaultColor As System.Drawing.Color
        Get
            Return MyBase.BackColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            dfltColor = value
            MyBase.BackColor = dfltColor
        End Set
    End Property

    Public Sub BeginEdit()
        Me.OnClick(New EventArgs)
    End Sub

    ''' <summary>
    ''' 編集完了の合図
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EndEdit() ' Implements IfTenkeyLabel.EndEdit
        Me.BackColor = dfltColor
        fIsEditing = False
        RaiseEvent InputCompleted(Me)
    End Sub

    ''' <summary>
    ''' 入力された内容を全てクリアする
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ClearText() ' Implements IfTenkeyLabel.ClearText
        Me.Text = String.Empty
    End Sub

    Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
        If MyBase.BackColor = Color.Red Then
            Exit Sub
        End If
        MyBase.BackColor = InputColor
        MyBase.OnMouseEnter(e)
    End Sub

    Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
        If MyBase.BackColor = Color.Red Then
            Exit Sub
        End If
        If Not fIsEditing Then
            Me.BackColor = dfltColor
        End If

        MyBase.OnMouseLeave(e)
    End Sub

    Protected Overrides Sub OnClick(ByVal e As EventArgs)
        Me.BackColor = InputColor
        fIsChanged = False
        fIsEditing = True
        Me.Focus()
        MyBase.OnClick(e)
    End Sub

    Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
        fIsChanged = True
        MyBase.OnTextChanged(e)
    End Sub

    'Public Interface IfTenkeyLabel

    '    ReadOnly Property IsEditing As Boolean
    '    ReadOnly Property IsChanged As Boolean
    '    Sub EndEdit()
    '    Sub ClearText()
    'End Interface

End Class
